<template>
	<view v-if="pageShow">
		<u-sticky bgColor="#fff">
			<u-tabs :list="list1" lineColor="#ab956d" @click="changetab" :current="current"
				:activeStyle="{
				    color: '#000000',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#666666',
							fontWeight: '500',
				            transform: 'scale(1)'
				        }" itemStyle="height: 44px;"></u-tabs>
		</u-sticky>
		<view class="banner sanshier xiaohei bold textcenter margin_top" style="background-color: #f9f9f9;">{{currentflname}}</view>
		<view class="mainpadding2">
			<view class="flexbetween flex_wrap ">
				<view class="spbox margin_top" v-for="item in list"
					@click="jumpdetail('/pages/index/shangpinxq?id=',item.id)">
					<image class="sptp" :src="item.picUrl" mode=""></image>
					<view class="" style="padding: 30rpx 15rpx;">
						<view class="ershiba xiaohei xiankuan textcenter">{{item.name}}</view>
						<view class="strongtext xiaojin textcenter margin_top">￥{{item.counterPrice}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [],
				listid:"",
				categoryId:"",
				list:[],
				currentflname:{},
				pageShow:false,
				current:0
			}
		},
		onLoad(options) {
			this.listid = options.id
			uni.setNavigationBarTitle({
				title:options.name
			})
			if(options.categoryId){
				this.categoryId = options.categoryId
			}
			this.getcaregory()
		},
		methods: {
			getcaregory(){
				httpRequest.request('/wx/goods/category', 'GET', {
					id: this.listid,
				}).then(res => {
					if(res.data.brotherCategory.length){
						if(this.categoryId){
							res.data.brotherCategory.forEach(item,index=>{
								if(item.id==this.categoryId){
									this.current = index
								}
							})
						}else{
							this.categoryId = res.data.brotherCategory[0].id
						}
						this.list1 = res.data.brotherCategory
					}
					this.currentflname = res.data.currentCategory.name
					this.pageShow = true
					this.init()
				})
			},
			init(){
				httpRequest.request('/wx/goods/list', 'GET', {
					categoryId: this.categoryId,
					page: 1,
					size: 1000
				}).then(res => {
					this.list = res.data.goodsList
				})
			},
			changetab(e){
				console.log(e);
				this.currentflname = e.name
				this.categoryId = e.id
				this.init()
			}
		}
	}
</script>

<style lang="scss" scoped>
.banner{
		padding: 50rpx;
		width: 100%;
		box-sizing: border-box;
	}
</style>
